package com.iwith.dongmoon.listadpater;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.iwith.dongmoon.activity.R;
import com.iwith.dongmoon.gsonlist.MemberListItem;

public class ThreeTextMemberListAdapter extends ArrayAdapter<MemberListItem> {
	private Context mContext;
	private ArrayList<MemberListItem> items;
	private LayoutInflater mInflater;

	public ThreeTextMemberListAdapter(Context context, int textViewResourceId, ArrayList<MemberListItem> list) {
		super(context, textViewResourceId, list);
		// TODO Auto-generated constructor stub

		this.mContext = context;
		this.items = list;
		this.mInflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
	}

	class ViewHolder {
		TextView caname;
		TextView name;
		TextView datetime;
	}
	
	@Override
	public MemberListItem getItem(int position) {
		if(items==null) 	return null;
		else 				return items.get(position);
	}
	
	@Override
	public int getCount(){
		if(items==null)		return 0;
		else				return super.getCount();
	}


	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.listitem_threetext, null);
			holder.caname = (TextView) convertView.findViewById(R.id.listitemthreetext_text1);
			holder.name = (TextView) convertView.findViewById(R.id.listitemthreetext_text2);
			holder.datetime = (TextView) convertView.findViewById(R.id.listitemthreetext_text3);
						
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final MemberListItem item = items.get(position);

		if (item != null) {
			holder.caname.setText(item.getUsername());
			holder.name.setText(item.getGraduation().toString()+"기");
			holder.datetime.setText(item.getJobType());
			convertView.setBackgroundColor((position & 1) == 1 ? 0xffececec : Color.WHITE);
		}

		return convertView;
	}
}
